package com.caius.xiaohashu.note.biz.rcp;

import com.caius.framework.common.response.Response;
import com.caius.xiaohashu.user.api.UserFeignApi;
import com.caius.xiaohashu.user.dto.req.FindUserByIdReqDTO;
import com.caius.xiaohashu.user.dto.resp.FindUserByIdRspDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author Caius
 * @description
 * @since Created in 2025-05-21
 */
@Component
public class UserRcpService {

    @Resource
    private UserFeignApi userFeignApi;

    /**
     * 通过用户 ID 查询用户信息
     * @param id
     * @return
     */
    public FindUserByIdRspDTO findById(Long id) {
        FindUserByIdReqDTO findUserByIdReqDTO = new FindUserByIdReqDTO();
        findUserByIdReqDTO.setId(id);

        Response<FindUserByIdRspDTO> response = userFeignApi.findById(findUserByIdReqDTO);

        if (Objects.isNull(response) || !response.isSuccess()) {
            return null;
        }

        return response.getData();
    }
}
